<h2>Why is this an issue?</h2>
<p>When <a href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement">Select Case</a> statements
have large sets of multi-line <code>Case</code> clauses, the code becomes hard to read and maintain.</p>
<p>For example, the <a href="https://www.sonarsource.com/docs/CognitiveComplexity.pdf">Cognitive Complexity</a> is going to be particularly high.</p>
<p>In such scenarios, it’s better to refactor the <code>Select Case</code> to only have single-line case clauses.</p>
<p>When all the <code>Case</code> clauses of a <code>Select Case</code> statement are single-line, the readability of the code is not affected.</p>
<h3>Exceptions</h3>
<p>This rule ignores:</p>
<ul>
  <li> <code>Select Case</code> statements over <code>Enum</code> arguments </li>
  <li> fall-through cases </li>
  <li> <code>Return</code> and <code>Throw</code> statements in <code>Case</code> clauses </li>
</ul>
<h2>How to fix it</h2>
<p>Extract the logic of multi-line <code>Case</code> clauses into separate methods.</p>
<h3>Code examples</h3>
<p>The examples below use the "Maximum number of case" property set to <code>4</code>.</p>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
Public Function MapChar(ch As Char, value As Integer) As Integer ' Noncompliant
    Select Case ch
        Case "a"c
            Return 1
        Case "b"c
            Return 2
        Case "c"c
            Return 3
        ' ...
        Case "-"c
            If value &gt; 10 Then
                Return 42
            ElseIf value &lt; 5 AndAlso value &gt; 1 Then
                Return 21
            End If
            Return 99
        Case Else
            Return 1000
    End Select
End Function
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
Public Function MapChar(ch As Char, value As Integer) As Integer
    Select Case ch
        Case "a"c
            Return 1
        Case "b"c
            Return 2
        Case "c"c
            Return 3
        ' ...
        Case "-"c
            Return HandleDash(value)
        Case Else
            Return 1000
    End Select
End Function

Private Function HandleDash(value As Integer) As Integer
    If value &gt; 10 Then
        Return 42
    ElseIf value &lt; 5 AndAlso value &gt; 1 Then
        Return 21
    End If
    Return 99
End Function
</pre>
<h2>Resources</h2>
<h3>Documentation</h3>
<ul>
  <li> Sonar - <a href="https://www.sonarsource.com/docs/CognitiveComplexity.pdf">Cognitive Complexity</a> </li>
  <li> Microsoft Learn - <a
  href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement">Select…​Case Statement</a> </li>
</ul>

